package com.ruoyi.web.controller.home;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.orders.domain.Orders;
import com.ruoyi.orders.service.IOrdersService;
import com.ruoyi.system.domain.Room;
import com.ruoyi.system.service.IReservationService;
import com.ruoyi.system.service.IRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Classname HomeController
 * @Description
 * @Date 2025/5/29 0:24
 * @Created by Fikc
 */
@RestController
@RequestMapping("/home/home")
public class HomeController extends BaseController {
    @Autowired
    private IOrdersService ordersService;
    @Autowired
    private IReservationService reservationService;
    @Autowired
    private IRoomService roomService;
//    首页获取订单金额总和方法
    @GetMapping("/getTotalAmount")
    public BigDecimal list(Orders orders)
    {

        BigDecimal totalAmount= BigDecimal.valueOf(0.00);

        List<Orders> list = ordersService.selectOrdersList(orders);
        for (Orders orders1 : list) {
            BigDecimal account = orders1.getAccount();
            totalAmount=totalAmount.add(account);
        }
        return totalAmount;
    }
//    获取当前时间段房间的使用率
    @GetMapping("/getRoomNum")
    public Integer getRoomNum(@RequestParam("currentTime") String currentTimeStr) {
        System.out.println(currentTimeStr);
        String[] s = currentTimeStr.split(" ");
        String date=s[0];
        String time=s[1];
        System.out.println(date);
        int reservationNum = reservationService.getRoomRate(date, time);
        System.out.println("预约房间"+reservationNum);
        List<Room> rooms = roomService.selectRoomList(new Room());
        int roomNum = rooms.size();
        System.out.println("总房间"+roomNum);
        int roomRate = (int) Math.round((reservationNum * 100.0) / roomNum);
        System.out.println(roomRate);

        return roomRate;
    }
}